package com.salim.leetcode.$11;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ContainerWithMostWater {

    public static void main(String[] args){
        int[] height = {1,8,6,2,5,4,8,3,7};
        log.info("{}",new ContainerWithMostWater().maxArea(height));
    }

    public int maxArea(int[] height) {
        int leftMaxHeight = 0;
        int maxArea = 0;
        int rightMaxHeight = 0;
        for (int i=0;i<height.length;i++){
            if(height[i]>leftMaxHeight){
                leftMaxHeight = height[i];
                rightMaxHeight = 0;
                for(int j=0;j<height.length-1;j++){
                    //相交即无容积
                    if(height.length-1-j<=i){
                        break;
                    }
                    if(height[height.length-1-j]>rightMaxHeight){
                        rightMaxHeight = height[height.length-1-j];
                        maxArea = Math.max(maxArea,(height.length-j - i - 1)*Math.min(height[i],height[height.length-1-j]));
                    }
                    if(rightMaxHeight>height[i]){
                        break;
                    }
                }
            }
        }
        return maxArea;
    }
}
